package com.helei.test;

import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.ConnectException;
import java.util.List;

/**
 * @ Author：hl
 * @ Date：2025-01-03-下午2:35
 */
public class test {
    public static void main(String[] args) throws IOException, InterruptedException {
        String url = "https://www.xss86.com/161/161890/377267.html";
        for (int i = 0; i < 10; i++) {
            Document document = null;
            while (document == null) {
                try {
                    System.out.println("重试-------1");
                    document = Jsoup.connect(url).get();

                } catch (Exception e) {
                    System.out.println("重试-------2");
                    if (!(e instanceof ConnectException)) {
                        System.out.println("重试-------3");
                        e.getMessage();
                        return;
                    }
                }
            }
            Elements readTitle = document.getElementsByClass("readTitle");
            List<TextNode> textNodes = readTitle.textNodes();
            System.out.println(textNodes.stream().findFirst().get());
            Element htmlContent = document.getElementById("htmlContent");

            System.out.println(htmlContent);

            Element linkNext = document.getElementById("linkNext");
            System.out.println(linkNext);
            Attributes attributes = linkNext.attributes();
            String s = attributes.get("href");
            System.out.println(s + "--------------");
            url = s;
        }

    }
}
